#!/bin/sh

. /home/yangp01/self-cmd/base.sh

pu_sect=0
sb_dev=""
vd_width=0
vu_width=0
vsu_width=0
vsu_num=0

j=0
for line in `cat $1`
do
	case "$j" in
		0) pu_sect=$line ;;
		1) sb_dev=$line ;;
		2) vd_width=$line ;;
		3) vu_width=$line ;;
		4) vsu_width=$line ;;
		5) vsu_num=$line ;;
	esac
	j=$(($j + 1))
done

echo "bwrm_syscreate -f"
bwrm_syscreate -f
echo "bwrm_pgcreate -n pg0 -s $pu_sect -d $sb_dev"
bwrm_pgcreate -n pg0 -s $pu_sect

for dev in `cat $2`
do
	echo "dd if=/dev/zero bs=512 count=1 oflag=direct of=$dev"
	dd if=/dev/zero bs=512 count=1 oflag=direct of=$dev
	echo "bwrm_pdcreate -g pg0 -d $dev"
	bwrm_pdcreate -g pg0 -d $dev
done

echo "bwrm_vgcreate -n vg0 -c 128 -d $vd_width -u $vu_width -g pg0"
bwrm_vgcreate -n vg0 -c 128 -d $vd_width -u $vu_width -g pg0

i=0
while [ $i -lt $vsu_num ] || [ $vsu_num -eq 0 ]
do
	ret=0
	try=0
	while [ 1 ]
	do
		echo "bwrm_vsucreate -g vg0 -n v$i -w $vsu_width -c 128"
		bwrm_vsucreate -g vg0 -n v$i -w $vsu_width -c 128
		ret=$?
		echo "ret=$ret"
		if [ $ret -eq 0 ]
		then
			break
		fi

		if [ $try -eq 3 ]
		then 
			echo "Failed to create v$i" > /dev/stderr
			exit -1
		fi
		try=$(($try + 1))
	done
	i=$(($i + 1))
	sync
done

